﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Poly2Tri
{
	// Token: 0x020003FF RID: 1023
	public class PointSet : Point2DList, ITriangulatable, IEnumerable<TriangulationPoint>, IList<TriangulationPoint>, IEnumerable, ICollection<TriangulationPoint>
	{
		// Token: 0x06001C68 RID: 7272 RVA: 0x000B2AFC File Offset: 0x000B0CFC
		public PointSet(List<TriangulationPoint> bounds)
		{
			foreach (TriangulationPoint p in bounds)
			{
				this.Add(p, -1, false);
				this.mBoundingBox.AddPoint(p);
			}
			this.mEpsilon = base.CalculateEpsilon();
			this.mWindingOrder = Point2DList.WindingOrderType.Unknown;
		}

		// Token: 0x17000404 RID: 1028
		// (get) Token: 0x06001C69 RID: 7273 RVA: 0x000AF9A1 File Offset: 0x000ADBA1
		// (set) Token: 0x06001C6A RID: 7274 RVA: 0x00002973 File Offset: 0x00000B73
		public IList<TriangulationPoint> Points
		{
			get
			{
				return this;
			}
			private set
			{
			}
		}

		// Token: 0x17000405 RID: 1029
		// (get) Token: 0x06001C6B RID: 7275 RVA: 0x000B2B94 File Offset: 0x000B0D94
		// (set) Token: 0x06001C6C RID: 7276 RVA: 0x000B2B9C File Offset: 0x000B0D9C
		public IList<DelaunayTriangle> Triangles { get; private set; }

		// Token: 0x17000406 RID: 1030
		// (get) Token: 0x06001C6D RID: 7277 RVA: 0x000B2BA5 File Offset: 0x000B0DA5
		// (set) Token: 0x06001C6E RID: 7278 RVA: 0x000B2BAD File Offset: 0x000B0DAD
		public string FileName { get; set; }

		// Token: 0x17000407 RID: 1031
		// (get) Token: 0x06001C6F RID: 7279 RVA: 0x000B2BB6 File Offset: 0x000B0DB6
		// (set) Token: 0x06001C70 RID: 7280 RVA: 0x000B2BBE File Offset: 0x000B0DBE
		public bool DisplayFlipX { get; set; }

		// Token: 0x17000408 RID: 1032
		// (get) Token: 0x06001C71 RID: 7281 RVA: 0x000B2BC7 File Offset: 0x000B0DC7
		// (set) Token: 0x06001C72 RID: 7282 RVA: 0x000B2BCF File Offset: 0x000B0DCF
		public bool DisplayFlipY { get; set; }

		// Token: 0x17000409 RID: 1033
		// (get) Token: 0x06001C73 RID: 7283 RVA: 0x000B2BD8 File Offset: 0x000B0DD8
		// (set) Token: 0x06001C74 RID: 7284 RVA: 0x000B2BE0 File Offset: 0x000B0DE0
		public float DisplayRotate { get; set; }

		// Token: 0x1700040A RID: 1034
		// (get) Token: 0x06001C75 RID: 7285 RVA: 0x000B2BE9 File Offset: 0x000B0DE9
		// (set) Token: 0x06001C76 RID: 7286 RVA: 0x000B2BF1 File Offset: 0x000B0DF1
		public double Precision
		{
			get
			{
				return this.mPrecision;
			}
			set
			{
				this.mPrecision = value;
			}
		}

		// Token: 0x1700040B RID: 1035
		// (get) Token: 0x06001C77 RID: 7287 RVA: 0x000AEDC8 File Offset: 0x000ACFC8
		public double MinX
		{
			get
			{
				return this.mBoundingBox.MinX;
			}
		}

		// Token: 0x1700040C RID: 1036
		// (get) Token: 0x06001C78 RID: 7288 RVA: 0x000AEDD5 File Offset: 0x000ACFD5
		public double MaxX
		{
			get
			{
				return this.mBoundingBox.MaxX;
			}
		}

		// Token: 0x1700040D RID: 1037
		// (get) Token: 0x06001C79 RID: 7289 RVA: 0x000AEDE2 File Offset: 0x000ACFE2
		public double MinY
		{
			get
			{
				return this.mBoundingBox.MinY;
			}
		}

		// Token: 0x1700040E RID: 1038
		// (get) Token: 0x06001C7A RID: 7290 RVA: 0x000AEDEF File Offset: 0x000ACFEF
		public double MaxY
		{
			get
			{
				return this.mBoundingBox.MaxY;
			}
		}

		// Token: 0x1700040F RID: 1039
		// (get) Token: 0x06001C7B RID: 7291 RVA: 0x000AEDFC File Offset: 0x000ACFFC
		public Rect2D Bounds
		{
			get
			{
				return this.mBoundingBox;
			}
		}

		// Token: 0x17000410 RID: 1040
		// (get) Token: 0x06001C7C RID: 7292 RVA: 0x0001D4CA File Offset: 0x0001B6CA
		public virtual TriangulationMode TriangulationMode
		{
			get
			{
				return TriangulationMode.Unconstrained;
			}
		}

		// Token: 0x17000411 RID: 1041
		public TriangulationPoint this[int index]
		{
			get
			{
				return this.mPoints[index] as TriangulationPoint;
			}
			set
			{
				this.mPoints[index] = value;
			}
		}

		// Token: 0x06001C7F RID: 7295 RVA: 0x000AEE1C File Offset: 0x000AD01C
		IEnumerator<TriangulationPoint> IEnumerable<TriangulationPoint>.GetEnumerator()
		{
			return new TriangulationPointEnumerator(this.mPoints);
		}

		// Token: 0x06001C80 RID: 7296 RVA: 0x000AEE29 File Offset: 0x000AD029
		public int IndexOf(TriangulationPoint p)
		{
			return this.mPoints.IndexOf(p);
		}

		// Token: 0x06001C81 RID: 7297 RVA: 0x000B2BFA File Offset: 0x000B0DFA
		public override void Add(Point2D p)
		{
			this.Add(p as TriangulationPoint, -1, false);
		}

		// Token: 0x06001C82 RID: 7298 RVA: 0x000B2C0B File Offset: 0x000B0E0B
		public virtual void Add(TriangulationPoint p)
		{
			this.Add(p, -1, false);
		}

		// Token: 0x06001C83 RID: 7299 RVA: 0x000B2C17 File Offset: 0x000B0E17
		protected override void Add(Point2D p, int idx, bool constrainToBounds)
		{
			this.Add(p as TriangulationPoint, idx, constrainToBounds);
		}

		// Token: 0x06001C84 RID: 7300 RVA: 0x000B2C28 File Offset: 0x000B0E28
		protected bool Add(TriangulationPoint p, int idx, bool constrainToBounds)
		{
			if (p == null)
			{
				return false;
			}
			if (constrainToBounds)
			{
				this.ConstrainPointToBounds(p);
			}
			if (this.mPointMap.ContainsKey(p.VertexCode))
			{
				return true;
			}
			this.mPointMap.Add(p.VertexCode, p);
			if (idx < 0)
			{
				this.mPoints.Add(p);
			}
			else
			{
				this.mPoints.Insert(idx, p);
			}
			return true;
		}

		// Token: 0x06001C85 RID: 7301 RVA: 0x000B2C9B File Offset: 0x000B0E9B
		public override void AddRange(IEnumerator<Point2D> iter, Point2DList.WindingOrderType windingOrder)
		{
			if (iter == null)
			{
				return;
			}
			iter.Reset();
			while (iter.MoveNext())
			{
				Point2D p = iter.Current;
				this.Add(p);
			}
		}

		// Token: 0x06001C86 RID: 7302 RVA: 0x000B2CC8 File Offset: 0x000B0EC8
		public virtual bool AddRange(List<TriangulationPoint> points)
		{
			bool flag = true;
			foreach (TriangulationPoint p in points)
			{
				flag = (this.Add(p, -1, false) && flag);
			}
			return flag;
		}

		// Token: 0x06001C87 RID: 7303 RVA: 0x000B2D30 File Offset: 0x000B0F30
		public bool TryGetPoint(double x, double y, out TriangulationPoint p)
		{
			uint key = TriangulationPoint.CreateVertexCode(x, y, this.Precision);
			return this.mPointMap.TryGetValue(key, out p);
		}

		// Token: 0x06001C88 RID: 7304 RVA: 0x000B2D60 File Offset: 0x000B0F60
		public void Insert(int idx, TriangulationPoint item)
		{
			this.mPoints.Insert(idx, item);
		}

		// Token: 0x06001C89 RID: 7305 RVA: 0x000B2D6F File Offset: 0x000B0F6F
		public override bool Remove(Point2D p)
		{
			return this.mPoints.Remove(p);
		}

		// Token: 0x06001C8A RID: 7306 RVA: 0x000B2D6F File Offset: 0x000B0F6F
		public bool Remove(TriangulationPoint p)
		{
			return this.mPoints.Remove(p);
		}

		// Token: 0x06001C8B RID: 7307 RVA: 0x000B2D7D File Offset: 0x000B0F7D
		public override void RemoveAt(int idx)
		{
			if (idx < 0 || idx >= base.Count)
			{
				return;
			}
			this.mPoints.RemoveAt(idx);
		}

		// Token: 0x06001C8C RID: 7308 RVA: 0x000AF0E0 File Offset: 0x000AD2E0
		public bool Contains(TriangulationPoint p)
		{
			return this.mPoints.Contains(p);
		}

		// Token: 0x06001C8D RID: 7309 RVA: 0x000B2DA0 File Offset: 0x000B0FA0
		public void CopyTo(TriangulationPoint[] array, int arrayIndex)
		{
			int num = Math.Min(base.Count, array.Length - arrayIndex);
			for (int i = 0; i < num; i++)
			{
				array[arrayIndex + i] = (this.mPoints[i] as TriangulationPoint);
			}
		}

		// Token: 0x06001C8E RID: 7310 RVA: 0x000B2DE8 File Offset: 0x000B0FE8
		protected bool ConstrainPointToBounds(Point2D p)
		{
			double x = p.X;
			double y = p.Y;
			p.X = Math.Max(this.MinX, p.X);
			p.X = Math.Min(this.MaxX, p.X);
			p.Y = Math.Max(this.MinY, p.Y);
			p.Y = Math.Min(this.MaxY, p.Y);
			return p.X != x || p.Y != y;
		}

		// Token: 0x06001C8F RID: 7311 RVA: 0x000B2E7C File Offset: 0x000B107C
		protected bool ConstrainPointToBounds(TriangulationPoint p)
		{
			double x = p.X;
			double y = p.Y;
			p.X = Math.Max(this.MinX, p.X);
			p.X = Math.Min(this.MaxX, p.X);
			p.Y = Math.Max(this.MinY, p.Y);
			p.Y = Math.Min(this.MaxY, p.Y);
			return p.X != x || p.Y != y;
		}

		// Token: 0x06001C90 RID: 7312 RVA: 0x000B2AEC File Offset: 0x000B0CEC
		public virtual void AddTriangle(DelaunayTriangle t)
		{
			this.Triangles.Add(t);
		}

		// Token: 0x06001C91 RID: 7313 RVA: 0x000B2F10 File Offset: 0x000B1110
		public void AddTriangles(IEnumerable<DelaunayTriangle> list)
		{
			foreach (DelaunayTriangle t in list)
			{
				this.AddTriangle(t);
			}
		}

		// Token: 0x06001C92 RID: 7314 RVA: 0x000B2F64 File Offset: 0x000B1164
		public void ClearTriangles()
		{
			this.Triangles.Clear();
		}

		// Token: 0x06001C93 RID: 7315 RVA: 0x00003781 File Offset: 0x00001981
		public virtual bool Initialize()
		{
			return true;
		}

		// Token: 0x06001C94 RID: 7316 RVA: 0x000B2F74 File Offset: 0x000B1174
		public virtual void Prepare(TriangulationContext tcx)
		{
			if (this.Triangles == null)
			{
				this.Triangles = new List<DelaunayTriangle>(this.Points.Count);
			}
			else
			{
				this.Triangles.Clear();
			}
			tcx.Points.AddRange(this.Points);
		}

		// Token: 0x04001D90 RID: 7568
		protected Dictionary<uint, TriangulationPoint> mPointMap = new Dictionary<uint, TriangulationPoint>();

		// Token: 0x04001D96 RID: 7574
		protected double mPrecision = TriangulationPoint.kVertexCodeDefaultPrecision;
	}
}
